const ejs = require('ejs')

module.exports = async (ctx, renderer, template) => {
    ctx.headers['Content-Type'] = 'text/html'
    const context = {
        url: ctx.path
    }
    try{
        const appString = await renderer.renderToString(context)
        const html = ejs.render(template, {
            // dom
            appString,
            // styles
            style: context.renderStyles(),
            // scripts
            scripts: context.renderScripts()
        })
        ctx.body = html
    }catch(err) {
        console.log('err: ', err)
        throw err
    }
}
